package com.ybxy;

import java.lang.reflect.Array;
import java.util.*;

public class CollectionsDemo {
    public static void main(String[] args) {

        //多态
        //test0();
        //test1();
        test2();
    }

    private static void test0() {
        List<String> list = new ArrayList<String>();

        Collections.addAll(list, "张三", "李四", "王五", "赵六");

        list.forEach(System.out::println);

        System.out.println("-------------------------------------------");

        Collections.shuffle(list);
        list.forEach(System.out::println);
    }

    public static void test1() {
        List<Integer> list = new ArrayList<>();
        Collections.addAll(list, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10);

        Collections.sort(list);
        list.forEach(System.out::println);
        System.out.println("-------------------------------------------");


        //倒叙排列,匿名内部类
        Collections.sort(list, new Comparator<Integer>() {
            @Override
            public int compare(Integer o1, Integer o2) {
                return o2-o1;
            }
        });
        list.forEach(System.out::println);


    }

    public static void test2() {

        List<Student> list1 = new ArrayList<>();
        list1.add(new Student("张三", 18));
        list1.add(new Student("王五", 19));
        list1.add(new Student("赵六", 21));
        list1.add(new Student("李四", 20));

        Collections.sort(list1);
        list1.forEach(System.out::println);

        Collection<Student> synchronizededList = Collections.synchronizedCollection(list1);
    }

//    public static void test3() {
//        List<Student> list2 = new ArrayList<>();
//
//        list2.add(new Student("张三", 18));
//        list2.add(new Student("赵六", 21));
//        list2.add(new Student("王五", 19));
//        list2.add(new Student("李四", 20));
//
//        Collections.sort(list2, new Comparator<Student>() {
//            @Override
//            public int compare(Student o1, Student o2) {
//                return o1.getAge()-o2.getAge();
//            }
//        });
//        list2.forEach(System.out::println);
//    }

}
